﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MH
{
    [Serializable]
    public class Props
    {
        public Props()
        {
            Items = new List<Prop>();
        }

        public List<Prop> Items;

        public int GetIndex(string name)
        {
            for (int i = 0; i < Items.Count; i++)
            {
                if (Items[i].Name == name)
                {
                    return i;
                }
            }
            return -1;
        }

        public int Count
        {
            get
            {
                return Items.Count;
            }
        }

        public Prop this[int index]
        {
            get
            {
                Prop prop = Items[index];
                prop.GenerateNewGUID();
                return prop;
            }
        }
        public Prop this[string name]
        {
            get
            {
                int i = GetIndex(name);
                if (i < 0)
                {
                    return null;
                }
                return this[i];
            }
        }

        public void Clear()
        {
            Items.Clear();
        }
        public void Add(Prop prop)
        {
            if (Items == null)
            {
                Items = new List<Prop>();
            }
            int i = GetIndex(prop.Name);
            if (i > -1)
            {
                return;
            }
            Items.Add(prop);
        }

        public void Del(int index)
        {
            Items.RemoveAt(index);
        }
        public void Del(string name)
        {
            int i = GetIndex(name);
            if (i < 0)
            {
                return;
            }
            Items.RemoveAt(i);
        }

    }
}
